<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ContactApiController extends AbstractRestfulController
{
    public function getList()
    {			
		header('Access-Control-Allow-Origin: *');
		$contactTable=$this->getServiceLocator()->get('Models\Model\ContactFactory');
		
    }
    public function get($course_id)
    {		
		header('Access-Control-Allow-Origin: *');
		$data=array();		
		$contactTable=$this->getServiceLocator()->get('Models\Model\ContactFactory');
		
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');	
		$contactTable=$this->getServiceLocator()->get('Models\Model\ContactFactory');
		global $ContactFormSubject;
		global $ContactFormMessage;				
		$saveContactform = $contactTable->saveContactform($data);
		if($saveContactform!=0){
			$userfname=ucfirst($data['firstname']);
			$userlname=ucfirst($data['lastname']);
			$cname=$data['course_name'];
			$cdetailes=$data['course_detailes'];
			$add=$data['address'];
			$addinfo=$data['addressinfo'];
			$email=$data['email'];
			$phone=$data['phonenumber'];
			$country=$data['country'];
			$city=$data['city'];
			$pcode=$data['postcode'];
			$sdate=$data['startdate'];
			$edate=$data['enddate'];
			$ContactFormMessage = str_replace("<COURSENAME>","$cname", $ContactFormMessage);
			$ContactFormMessage = str_replace("<COURSEDETAILES>","$cdetailes", $ContactFormMessage);
			$ContactFormMessage = str_replace("<FIRSTNAME>","$userfname", $ContactFormMessage);
			$ContactFormMessage = str_replace("<LASTNAME>","$userlname", $ContactFormMessage);
			$ContactFormMessage = str_replace("<ADDRESS>","$add", $ContactFormMessage);
			$ContactFormMessage = str_replace("<ADDRESSINFO>","$addinfo", $ContactFormMessage);
			$ContactFormMessage = str_replace("<EMAIL>","$email", $ContactFormMessage);
			$ContactFormMessage = str_replace("<PHONE>","$phone", $ContactFormMessage);
			$ContactFormMessage = str_replace("<COUNTRY>","$country", $ContactFormMessage);
			$ContactFormMessage = str_replace("<CITY>","$city", $ContactFormMessage);
			$ContactFormMessage = str_replace("<POSTCODE>","$pcode", $ContactFormMessage);
			$ContactFormMessage = str_replace("<STARTDATE>","$sdate", $ContactFormMessage);
			$ContactFormMessage = str_replace("<ENDDATE>","$edate", $ContactFormMessage);
			$to='naveenleela3@gmail.com';	
				if(sendMail($to,$ContactFormSubject,$ContactFormMessage)){
					return new JsonModel(array(
						'output' 	=> 	'success',
						'UserId'	=>	$saveContactform,
						'value' 	=> 	1,
						'message' 	=> 	"Email sent successfully",
					));
				}else{
					return new JsonModel(array(
						'output' 	=> 'not success',
						'value' 	=> 0,
						'message' 	=> 	"Email sent failed",
					));
				}
		}else{
			return new JsonModel(array(
				'output' 	=> 'not success',
				'value' 	=> 0,
				'message' 	=> 	"Email sent failed",
			));
		}		

    }
    public function update($answer, $data)
    {
		header('Access-Control-Allow-Origin: *');	
		
    }
    public function delete($id)
    {
       
    }
}